package 笔试.小米笔试.第二题;

import java.util.Scanner;

public class Main
{
    static boolean[][] booleans;
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        char[][] chars={{'A','B','C','E'},{'S','F','C','S'},{'A','D','E','E'}};
        if (s.length()<0)
        {
            int cnt = 0;
            boolean word = false;
            boolean WORD = false;
            boolean num = false;
            boolean symbol = false;
        }
        System.out.println(exist(chars,s));
    }
    public static boolean exist(char[][] chars ,String word)
    {
        if (chars==null||chars.length==0||chars[0].length==0)
            return false;
        booleans =new boolean[chars.length][chars[0].length];
        if (word==null||word.length()==0)
            return true;
        if (mymethod(chars,word,0,0,0))
            return true;
        else
            return false;
    }
    public static boolean mymethod(char[][] chars, String word, int start, int i1, int i2)
    {
        if (start==word.length())
            return true;
        char temp=word.charAt(start);
        if (start==0)
        {
            for (int i = 0; i < chars.length; i++)
            {
                for (int j = 0; j < chars[0].length; j++)
                {
                    if (chars[i][j]==temp)
                    {
                        booleans[i][j]=true;
                        if (mymethod(chars,word,start+1,i,j))
                            return true;
                        booleans[i][j]=false;
                    }
                }
            }
            return false;
        }
        else
        {
            if (i2-1>=0)
            {
                if (chars[i1][i2-1]==temp&&!booleans[i1][i2-1])
                {
                    booleans[i1][i2-1]=true;
                    if (mymethod(chars,word,start+1,i1,i2-1))
                        return true;
                    booleans[i1][i2-1]=false;
                }
            }
            if (i1-1>=0)
            {
                if (chars[i1-1][i2]==temp&&!booleans[i1-1][i2])
                {
                    booleans[i1-1][i2]=true;
                    if (mymethod(chars,word,start+1,i1-1,i2))
                        return true;
                    booleans[i1-1][i2]=false;
                }
            }
            if (i2+1<chars[0].length)
            {
                if (chars[i1][i2+1]==temp&&!booleans[i1][i2+1])
                {
                    booleans[i1][i2+1]=true;
                    if (mymethod(chars,word,start+1,i1,i2+1))
                        return true;
                    booleans[i1][i2+1]=false;
                }
            }
            if (i1+1<chars[0].length)
            {
                if (chars[i1+1][i2]==temp&&!booleans[i1+1][i2])
                {
                    booleans[i1+1][i2]=true;
                    if (mymethod(chars,word,start+1,i1+1,i2))
                        return true;
                    booleans[i1+1][i2]=false;
                }
            }
            return false;
        }
    }
}
